<?php
/**
 * @author Thibaut Cromphaut, Gaïtano Boeraeve, Mathias Helin, Dimitry Dierickx
 * @copyright  Copyright (c) 2011 Artevelde University College Ghent 
 */

class Application_Form_Register extends Zend_Form
{
    public function init()
    {
        $this->addElement(new Application_Form_Element_TitleSelect('user_title', array(
            'label'      => 'Title',
            'required'   => false,
            'filters'    => array('StringTrim')
        )));
        
        $this->addElement('text', 'user_givenname', array(
            'label'      => 'Givenname',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('StringLength', false, array(1, 45)),
            ),
        ));
        
        $this->addElement('text', 'user_familyname', array(
            'label'      => 'Familyname',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('StringLength', false, array(1, 45)),
            ),
        ));
        
        $this->addElement(new Application_Form_Element_UserEmail('user_primary_email', array(
            'label'      => 'Email',
            'required'   => true,
            'value'      => "***1",
            'filters'    => array('StringTrim'),
            'validators' => array(new Ahs_Validators_UserEmail()),
        )));
        
        $this->addElement('password', 'user_password', array(
            'label'      => 'Password',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                'Alnum',
                array('StringLength', false, array(8, 45)),
            ),
        ));

        $this->addElement('password', 'user_password_repeat', array(
            'label'      => 'Repeat Password',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                'Alnum',
                array('StringLength', false, array(8, 45)),
                array('Identical', true, array('user_password')),
            ),
        ));
        
        $this->addElement(new Application_Form_Element_SecretQuestionSelect('user_secretquestion_id', array(
            'label'      => 'Secret question',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                new Zend_Validate_Regex('/^[0-9]+$/'),
            ),
        )));
        
        $this->addElement('text', 'user_secretanswer', array(
            'label'      => 'Secret answer',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('StringLength', false, array(1, 45)),
            ),
        ));
        
        $this->addElement('submit', 'user_submit', array(
            'label'      => 'Create my account',
        ));

        // CSRF (Cross-Site Request Forgery)
        $this->addElement('hash', 'no_csrf_registration', array(
            'salt' => 'unique',
        ));
    }
}